define(["dzBaseView", "cUtilCryptBase64", "cMemberService", "scripts/vbkUtil", "scripts/vbridge", "scripts/cookie", "models/vStore", "models/vModel", "scripts/vModelFacade", "text!templates/orderDetailContainer.html", "text!templates/orderDetail_A.html", "text!templates/orderDetail_B.html", "text!templates/orderSupple.html", "cGuiderService", "UIAlert", "scripts/native"],
    function(cPageView, cUtilCryptBase64, member, vbkUtil, vbridge, ck, store, m, mFacade, container, orderDetail_A, orderDetail_B, orderSupple, Guider, cUIAlert, native) {

        var detailModel = m.GetRobRequireDetailModel.getInstance(),
            confirmRobModel = m.ConfirmRobModel.getInstance(),
            getRefuseReasonModel = m.GetRefuseReasonModel.getInstance(),
            refuseRobModel = m.RefuseRobModel.getInstance(),
            GetTotalUnreadcountModel = m.GetTotalUnreadcountModel.getInstance(),
            cookieUserInfor,
            alertObject = null,
            isRobing = false,
            isRefusing = false,
            isLogining = false,
            verifyToken = "",	//验证码token
            jsVersion = "",		//验证码js版本
            verifyFlag = false,	//是否出过验证码
            slidObj = "";		//全局定义验证码对象

        //新老版本判断
        var isNewVersion = false;
        var protocol = window.location.protocol.toLowerCase(); //当前协议
        var isIgnoreLogin = (Lizard.P('sourcefrom') && (Lizard.P('sourcefrom').toLowerCase() === 'wechat' || Lizard.P('sourcefrom').toLowerCase() === 'sms')) ? true : false;

        return cPageView.extend({
            /**
             pageid: '10320641804',
             hpageid: '10320641804',
             */
            events: {
                "click .rob_detail_back": "backToList",
                // "click .rob_require": "robRequire",
                "click .refuse_require": "showRefuseRequire",
                "click .refuse_require_tip": "hideRefuseReason",
                "click .single_refuse_tip": "refuseRequire",
                "click .js_rob_limit_close": "closeRobLimitTip",
                "click .improve_demand": "goToImproveDemand",
                "click .j_imMessageList": 'imMessageListEnter'
                // "click .j_imChat": "imChatWakeUp"
            },

            getImChatUrl: function() {
                var self = this,
                    imChatH5Url,
                    fatImChatUrl = "http://m.ctrip.fat27.qa.nt.ctripcorp.com/webapp/tours/csplatform/",
                    uatImChatUrl = "http://m.uat.qa.nt.ctripcorp.com/webapp/tours/csplatform/",
                    prodImChatUrl = "http://m.ctrip.com/webapp/tours/csplatform/";

                if (self.getEvnCode() == 0) {
                    imChatH5Url = fatImChatUrl;
                } else if (self.getEvnCode() == 2) {
                    imChatH5Url = uatImChatUrl;
                } else if (self.getEvnCode() == 3) {
                    imChatH5Url = prodImChatUrl;
                }

                return imChatH5Url;
            },

            imMessageListEnter: function() {
                var self = this,
                    imChatH5Url = self.getImChatUrl();

                if (!self.isInApp()) {
                    Lizard.jump(imChatH5Url + "imlist?from=" + encodeURIComponent(location.href), {
                        "loading": false
                    });

                } else {

                    if (self.isNewAppVersion) {
                        self.chatList();
                    } else {
                        Lizard.jump(imChatH5Url + "imlist?from=" + encodeURIComponent(location.href), {
                            "loading": false
                        });
                    }
                }
            },

            //IM接入 必传uid
            imChatWakeUp: function(obj) {
                var self = this,
                    orderType = Lizard.P('orderType');

                if (obj == $('.j_imChat')) {
                    uid = obj.attr('data-uid');
                } else {
                    uid = $('.j_imChat').attr('data-uid');
                }
                var buid = cUtilCryptBase64.Base64.encode(uid, false);


                var imChatH5Url,
                    fatImChatUrl = "http://m.ctrip.fat27.qa.nt.ctripcorp.com/webapp/tours/csplatform/",
                    uatImChatUrl = "https://m.uat.qa.nt.ctripcorp.com/webapp/tours/csplatform/",
                    prodImChatUrl = "https://m.ctrip.com/webapp/tours/csplatform/";
                self.myTracklog({
                    biz: 'imChatWakeUp'
                });

                var imChatH5Url = self.getImChatUrl();

                if (!self.isInApp()) {

                    if (orderType == 'GrabOrder') {
                        Lizard.jump(imChatH5Url + "imDetail?buid=" + buid + "&channelid=77&from=" + encodeURIComponent(location.href), {
                            "loading": false
                        });
                    } else {
                        Lizard.jump(imChatH5Url + "imDetail?buid=" + buid + "&channelid=76&from=" + encodeURIComponent(location.href), {
                            "loading": false
                        });
                    }


                } else {

                    if (self.isNewAppVersion) {
                        self.singleChat(uid);
                    } else {

                        if (orderType == 'GrabOrder') {
                            Lizard.jump(imChatH5Url + "imDetail?buid=" + buid + "&channelid=77&from=" + encodeURIComponent(location.href), {
                                "loading": false
                            });
                        } else {
                            Lizard.jump(imChatH5Url + "imDetail?buid=" + buid + "&channelid=76&from=" + encodeURIComponent(location.href), {
                                "loading": false
                            });
                        }
                    }
                }
            },

            singleChat: function(uid) {
                vbkUtil.setupWebViewJavascriptBridge(function(bridge) {
                    bridge.callHandler('CallIM', window.VBase64Tool._base64encode(JSON.stringify({
                        'method': 'chat',
                        'uid': uid
                    })), function(response) {
                        console.log(response);
                    });
                });
            },

            chatList: function(e) {
                vbkUtil.setupWebViewJavascriptBridge(function(bridge) {
                    bridge.callHandler('CallIM', window.VBase64Tool._base64encode(JSON.stringify({
                        'method': 'chatmessage'
                    })), function(response) {
                        console.log(response);
                    });
                });
            },

            //有积分
            point: function() {
                var self = this;
                from = Lizard.P('from');
                self.$el.find('#point').show();
                if ($('.rob_require').hasClass('j_imChat')) {
                    var $this = $('.j_imChat');
                    setTimeout(function() {
                        self.$el.find('#point').hide();
                        self.$el.find('#upGrade').show();
                    }, 3000)
                    $(".upGrade_sure_btn").click(function() {
                        self.$el.find('#upGrade').hide();
                        self.imChatWakeUp($this);
                    });
                } else {
                    $(".point_sure_btn").click(function() {
                        self.$el.find('#point').hide();
                        Lizard.goTo("RobList?fromPage=rob_detail&orderType=" + Lizard.P('orderType') + "&from=" + from, {
                            "loading": false
                        });
                    });
                }
            },

            //无积分
            noPoint: function() {
                var self = this;
                from = Lizard.P('from');
                if ($('.rob_require').hasClass('j_imChat')) {
                    var $this = $('.j_imChat');
                    self.$el.find('#upGrade').show();
                    $(".upGrade_sure_btn").click(function() {
                        self.$el.find('#upGrade').hide();
                        self.imChatWakeUp($this);
                    });
                } else {
                    self.$el.find('.rob_success_tip').show();
                    setTimeout(function() {
                        Lizard.goTo("RobList?fromPage=rob_detail&orderType=" + Lizard.P('orderType') + "&from=" + from, {
                            "loading": false
                        });
                    }, 2000);
                }
            },

            //抢单
            robRequire: function() {
                var self = this,
                    from = Lizard.P('from');
                var version = isNewVersion ? 'new' : 'old';
                self.myTracklog({
                    biz: 'robRequire',
                    version: version
                });
                if (!isRobing) {
                    isRobing = true;
                    Lizard.showLoading();
                    var param = {
                        requireDetailId: Lizard.P("requireDetailId"),
                        verifyToken : verifyToken,
                        jsVersion : jsVersion
                    }

                    if (Lizard.P('sourcefrom') && (Lizard.P('sourcefrom').toLowerCase() == 'wechat' || Lizard.P('sourcefrom').toLowerCase() == 'sms')) {
                        $.extend(param, {
                            platformProviderId: Lizard.P('providerid'),
                            platformUserId: Lizard.P('userid')
                        });
                    }
                    confirmRobModel.setParam(param);
                    mFacade.excute(self, confirmRobModel, function(json) {
                        isRobing = false;
                        from = Lizard.P('from');
                        Lizard.hideLoading();
                        if (json.IsSuccess) {
                            //判断供应商是否参加积分系统
                            if (json.IsPointUser && json.OrderPointList.length > 0) {
                                for (var i = 0; i < json.OrderPointList.length; i++) {
                                    if (json.OrderPointList[i].RuleType == 0) {
                                        self.$el.find('.day').html(json.OrderPointList[i].GrabDays);
                                        self.$el.find('.mark').eq(1).html("+");
                                        self.$el.find('.num').eq(1).html(json.OrderPointList[i].PointValue);
                                        self.$el.find('#continue').show();
                                        self.point();
                                    } else if (json.OrderPointList[i].RuleType == 1) {
                                        self.$el.find('.mark').eq(2).html("+");
                                        self.$el.find('.num').eq(2).html(json.OrderPointList[i].PointValue);
                                        self.$el.find('#notWorkingTime').show();
                                        self.point();
                                    } else if (json.OrderPointList[i].RuleType == 2) {
                                        self.$el.find('.text').eq(0).html("小人档接单奖励积分");
                                        self.$el.find('.mark').eq(0).html("+");
                                        self.$el.find('.num').eq(0).html(json.OrderPointList[i].PointValue);
                                        self.$el.find('#people').show();
                                        self.point();
                                        self.myTracklog({
                                            biz: 'small_robRequire'
                                        });
                                    } else if (json.OrderPointList[i].RuleType == 3) {
                                        self.$el.find('.text').eq(0).html("大人档接单消耗积分");
                                        self.$el.find('.num').eq(0).html(json.OrderPointList[i].PointValue);
                                        self.$el.find('#people').show();
                                        self.point();
                                    }
                                }
                            } else {
                                self.noPoint();
                            }

                            try {
                                self.myTracklog({
                                    biz: 'rob_detail_info',
                                    PlatformUserId: json.PlatformUserId,
                                    PlatformProviderId: json.PlatformProviderId,
                                    SortPercent: json.SortPercent,
                                    RequireDetailId: json.RequireDetailId,
                                    CreateTime: json.CreateTime
                                })
                            } catch (e) {}
                        } else {
                            if(json.IsVerifySuccess){
                                self.myTracklog({
                                    biz: 'robRequireFailed',
                                    PlatformUserId: json.PlatformUserId,
                                    PlatformProviderId: json.PlatformProviderId,
                                    RequireDetailId: json.RequireDetailId,
                                    CreateTime: json.CreateTime,
                                    Description: json.Description
                                });
                                if (json.Description == '此单已经被您抢过了') {
                                    if ($('.rob_require').hasClass('j_imChat')) {
                                        var $this = $('.j_imChat');
                                        self.imChatWakeUp($this);
                                    }
                                } else if (json.Description == '恭喜您，抢单成功！') {
                                    self.$el.find('#confirmErrorTip').hide();
                                } else {
                                    self.$el.find('#confirmErrorTip').show();
                                    self.$el.find('#confirmErrorTip h4').html(json.Description);
                                }

                                if (json.StatusCode == '200033') { //当前待处理订单数有上限  超过限制
                                    self.myTracklog({
                                        biz: 'rob_require_default_error',
                                        PlatformUserId: json.PlatformUserId,
                                        PlatformProviderId: json.PlatformProviderId,
                                        RequireDetailId: json.RequireDetailId,
                                        CreateTime: json.CreateTime,
                                        WaitingForHandlingOrderCount: json.WaitingForHandlingOrderCount //待处理订单量
                                    })
                                } else if (json.StatusCode == '200040') {
                                    self.showToast("对不起，您当前积分不足，余额：" + json.SurplusPoints + "！");
                                    self.$el.find('.rob_require').css("background", "grey");
                                    $(".rob_require").click(function(event) {
                                        return false;
                                    });
                                }
                            }else{
                                self.$el.find('#confirmErrorTip').show();
                                self.$el.find('#confirmErrorTip h4').html(json.Description);
                            }
                        }

                    }, function(obj, e) {
                        isRobing = false;
                        Lizard.hideLoading();

                        self.$el.find('.rob_success_tip').hide();
                    }, false, isIgnoreLogin)

                }
            },

            //拒绝此需求单
            refuseRequire: function(e) {
                var self = this,
                    from = Lizard.P('from');
                var version = isNewVersion ? 'new' : 'old';
                self.myTracklog({
                    biz: 'refuseRequire',
                    version: version
                });
                if (!isRefusing) {
                    isRefusing = true;
                    Lizard.showLoading();

                    var param = {
                        requireDetailId: Lizard.P("requireDetailId"),
                        reasonId: $(e.currentTarget).attr('data-reason'),
                        reasonDetail: $(e.currentTarget).text().trim()
                    }

                    if (Lizard.P('sourcefrom') && (Lizard.P('sourcefrom').toLowerCase() == 'wechat' || Lizard.P('sourcefrom').toLowerCase() == 'sms')) {
                        $.extend(param, {
                            platformProviderId: Lizard.P('providerid'),
                            platformUserId: Lizard.P('userid')
                        });
                    }

                    refuseRobModel.setParam(param);
                    mFacade.excute(self, refuseRobModel, function(json) {
                        isRefusing = false;
                        Lizard.hideLoading();
                        self.$el.find('.refuse_success_tip .tips01').html('拒绝原因：' + $(e.currentTarget).text().trim());
                        self.$el.find('.refuse_success_tip').show();

                        //拒绝需求单埋点
                        if (self.isInApp()) {
                            window['__bfi'].push(['_tracklog', 'cus_waitoffer_list_app', "refuse_reason=" + $(e.currentTarget).text().trim()]);
                        } else {
                            window['__bfi'].push(['_tracklog', 'cus_waitoffer_list_h5', "refuse_reason=" + $(e.currentTarget).text().trim()]);
                        }
                        setTimeout(function() {
                            Lizard.goTo("RobList?fromPage=rob_detail&orderType=" + Lizard.P('orderType') + "&from=" + from, {
                                "loading": false
                            });
                        }, 2000);
                    }, function(obj, e) {
                        isRefusing = false;
                        Lizard.hideLoading();
                        self.$el.find('.refuse_success_tip').hide();
                    }, false, isIgnoreLogin)
                }
            },

            showRefuseRequire: function() {
                var self = this;
                if (self.$el.find('.refuse_require_tip').attr('data-loaded') == 'T') {
                    self.$el.find('.refuse_require_tip').show();
                }
            },

            hideRefuseReason: function() {
                var self = this;

                if (self.isInApp()) {
                    window['__bfi'].push(['_tracklog', 'cus_waitoffer_list_app', "refuse_reason=未选择"]);

                } else {
                    window['__bfi'].push(['_tracklog', 'cus_waitoffer_list_h5', "refuse_reason=未选择"]);
                }
                self.$el.find('.refuse_require_tip').hide();
            },

            //拒绝抢单原因
            renderReason: function() {
                var self = this,
                    refuseTpl = '<%_.each(data,function(d){%><li data-reason="<%=d.Value%>" class="single_refuse_tip"><a><%=d.Key%></a></li><%})%>'

                var param = {}

                if (Lizard.P('sourcefrom') && (Lizard.P('sourcefrom').toLowerCase() == 'wechat' || Lizard.P('sourcefrom').toLowerCase() == 'sms')) {
                    $.extend(param, {
                        platformProviderId: Lizard.P('providerid'),
                        platformUserId: Lizard.P('userid')
                    });
                    getRefuseReasonModel.setParam(param);
                }

                mFacade.excute(self, getRefuseReasonModel, function(json) {
                    self.$el.find('.refuse_require_tip').attr('data-loaded', 'T');
                    self.$el.find('.refuse_require_tip .pic_select').html(_.template(refuseTpl)({
                        "data": json
                    }));
                }, function(obj, e) {
                    self.$el.find('.refuse_require_tip').attr('data-loaded', 'F');
                }, false, isIgnoreLogin)
            },

            backToList: function() {
                var self = this,
                    from = Lizard.P('from');
                if (isIgnoreLogin) {
                    Lizard.goTo("RobList?sourceFrom=" + Lizard.P('sourceFrom') + '&providerid=' + Lizard.P('providerid') + '&userid=' + Lizard.P('userid') + '&orderType=' + Lizard.P('orderType') + "&from=" + from, {
                        "loading": false
                    });
                } else {
                    Lizard.goTo("RobList?fromPage=rob_detail&orderType=" + Lizard.P('orderType') + "&from=" + from, {
                        "loading": false
                    });
                }
            },

            oldLogin: function() {
                var fromUrl = encodeURIComponent(location.href),
                    backUrl = encodeURIComponent(location.href); //我携登录页点击退回按钮的时候返回
                var host = window.location.host.toLowerCase();
                if (!member.isLogin()) {
                    if (host.indexOf('fat') >= 0 || host.indexOf('localhost') >= 0) {
                        fromUrl = encodeURIComponent('https://m.ctrip.fat67.qa.nt.ctripcorp.com/webapp/vacations/vbk/board');
                        backUrl = encodeURIComponent('https://m.ctrip.fat67.qa.nt.ctripcorp.com/webapp/vacations/vbk/chooseLogin');
                        this.jump('http://accounts.fat49.qa.nt.ctripcorp.com/H5Login/Index?from=' + fromUrl + '&backurl=' + backUrl);
                    } else if (host.indexOf('fws') >= 0) {
                        fromUrl = encodeURIComponent('https://m.ctrip.fat67.qa.nt.ctripcorp.com/webapp/vacations/vbk/board');
                        backUrl = encodeURIComponent('https://m.ctrip.fat67.qa.nt.ctripcorp.com/webapp/vacations/vbk/chooseLogin');
                        this.jump('http://accounts.fat49.qa.nt.ctripcorp.com/H5Login/Index?from=' + fromUrl + '&backurl=' + backUrl);
                    } else if (host.indexOf('uat.qa.nt.ctripcorp') >= 0) {
                        fromUrl = encodeURIComponent('https://m.ctrip.uat.qa.nt.ctripcorp.com/webapp/vacations/vbk/board');
                        backUrl = encodeURIComponent('https://m.ctrip.uat.qa.nt.ctripcorp.com/webapp/vacations/vbk/chooseLogin');
                        this.jump('https://accounts.uat.qa.nt.ctripcorp.com/H5Login/Index?from=' + fromUrl + '&backurl=' + backUrl);
                    } else if (host.indexOf('uat.ctripqa.com') >= 0) {
                        fromUrl = encodeURIComponent('https://m.ctrip.uat.qa.nt.ctripcorp.com/webapp/vacations/vbk/board');
                        backUrl = encodeURIComponent('https://m.ctrip.uat.qa.nt.ctripcorp.com/webapp/vacations/vbk/chooseLogin');
                        this.jump('https://accounts.uat.ctripqa.com/H5Login/Index?from=' + fromUrl + '&backurl=' + backUrl);
                    } else {
                        fromUrl = encodeURIComponent('https://m.ctrip.com/webapp/vacations/vbk/board');
                        backUrl = encodeURIComponent('https://m.ctrip.com/webapp/vacations/vbk/chooseLogin');
                        this.jump('https://accounts.ctrip.com/H5Login/Index?from=' + fromUrl + '&backurl=' + backUrl);
                    }
                }
            },

            //调native方法设置cookie userInfo
            callNativeUser: function(callback) {
                var self = this;
                if (self.isInApp()) {
                    native.callNative({
                        method: 'callGetUserInfo',
                        callback: function(response) {
                            //H5页面要用到cookie中的userInfo
                            cookieUserInfor = window.VAppTool.isAndroidApp() ? response && cUtilCryptBase64.Base64.decode(response) : response && JSON.parse(cUtilCryptBase64.Base64.decode(response)).userInfo;
                            // ck.addCookie('userInfo', userInfo, 30);
                            // cookieUserInfor = ck.getCookie("userInfo");
                            callback(cookieUserInfor);
                        }
                    })
                }
            },

            initOnShow: function(cookieUserInfor) {
                var self = this,
                    orderType = Lizard.P('orderType'),
                    deviceInfo,
                    cookieUserInfor;


                //登录态获取
                var userInfo,
                    ctripUid;

                cookieUserInfor = cookieUserInfor || JSON.parse(ck.getCookie("userInfo"));
                if (cookieUserInfor || cookieUserInfor != '') {
                    userInfo = cookieUserInfor,
                        ctripUid = userInfo.CtripUid;
                } else {
                    userInfo = "",
                        ctripUid = "";
                }

                if (ctripUid == '') {
                    if (!self.isInApp()) {
                        self.oldLogin();

                    } else {

                        if (self.isNewAppVersion) {
                            if (window.VAppTool.isIOSApp()) {
                                param = {
                                    'method': 'isShowVbk'
                                };
                            } else {
                                param = {
                                    'method': 'isShowVbkAndCanBack'
                                };
                            }
                            vbkUtil.setupWebViewJavascriptBridge(function(bridge) {
                                bridge.callHandler('callCtripLogin', window.VBase64Tool._base64encode(JSON.stringify(param)), function(response) {});
                            });

                        } else {
                            self.oldLogin();
                        }
                    }
                } else {
                    //获取IM（总）未读信息条数
                    mFacade.excute(self, GetTotalUnreadcountModel, function(json) {
                        var unreadCount = json.unreadCount,
                            value;

                        if (unreadCount > 0 && unreadCount < 100) {
                            value = unreadCount;
                        } else if (unreadCount == 0) {
                            value = '';
                        } else if (unreadCount > 100) {
                            value = '99+';
                        }
                        $('.j_imMessageList').text(value)
                    }, function(obj, e) {}, false, isIgnoreLogin);

                    if (Lizard.P("orderType") == 'TurnOrder') {
                        self.$el.find('.detail_container').on('click', '.j_imChat', function() {
                            var $this = $(this);
                            self.imChatWakeUp($this);
                        });
                    }

                    self.$el.find('.detail_container').on('click', '.rob_require', function() {
                        if(!slidingVerification){
                            self.robRequire();
                        }else{
                            if(verifyFlag == false){	//初始化验证码
                                slidObj = new slidingVerification({
                                    id: "verification-code", // 验证码DIV的id
                                    appId: 100000313, // appId
                                    businessSite: "dingzhi_roborderlist_limit", // businessSite
                                    width: '280px', // 滑块宽度，可选，填像素字符串，如'280px'，默认值'280px'
                                    height: '40px', // 滑块长度，可选，填像素字符串，如'40px'，默认值'40px'
                                    language: 'zh-CN', // 语种，默认‘zh-CN’（简体中文）
                                    chooseOpt: {
                                        width: '280px',// 选字图片宽度，可选，选字验证码 大图的宽度
                                        height: '200px', // 选字图片高度，可选，选字验证码 大图的高度 如果选字width，height不填，生成的图片将根据后端默认配置进行屏幕大小自适应；如果选字width，height填写了，需要先找 ldq刘丹青 进行配置响应大小的图片
                                        type: "pop" // "over"： 浮窗(默认)；"pop"：弹出
                                    },
                                    selectBeforeHandler: function () {  // 选字弹框出现时调用的方法，可选，~2.3.0中移除
                                        alert("this is selectBeforeHandler");
                                    },
                                    hideBgHandler: function () { // 选字弹框消失时调用的方法，可选，~2.3.0中移除
                                        alert("this is hideBgHandler");
                                    },
                                    /**
                                     * 状态监听函数
                                     * @param state 0：滑块验证码显示；1：选字验证码弹框出现；2：选字验证码弹框消失
                                     */
                                    stateChange: function (state) {  // ~2.3.0中添加
                                        if(state==0) {
                                            //console.log("滑块显示");
                                            if ($(".cpt-drop-box").length > 1) {
                                                $(".cpt-drop-box").eq(0).siblings().remove();
                                            }
                                            $(".verityMask").show();
                                        } else if(state==1) {
                                            //console.log("选字验证码弹框出现");
                                            $(".verityMask").hide();
                                            $(".rob_list_loading ").hide();
                                        } else if(state==2) {
                                            //console.log("选字验证码弹框消失");
                                            $(".rob_list_loading ").hide();
                                        }
                                    },
                                    resultHandler: function(e) {
                                        //console.log("token:", e.token, 'e.checkState:', e.checkState, 'e.version', e.version);
                                        verifyToken = e.token;
                                        jsVersion = e.version;
                                        if(e.checkState == "success"){
                                            $(".verityMask").hide();
                                            self.robRequire();
                                        }else if(e.checkState == "hidden"){
                                            self.robRequire();
                                        }
                                    }
                                });
                                verifyFlag = true;
                            }else{
                                slidObj.refresh();
                            }
                        }
                    });
                }
            },

            onCreate: function() {
                var self = this;
                self.$el.html(container);
            },

            onShow: function() {
                var self = this,
                    orderType = Lizard.P('orderType'),
                    deviceInfo,
                    cookieUserInfor;


                self.headFix();
                self.renderContainer();
                self.renderReason();
                if (orderType == 'GrabOrder') { //待抢单列表
                    self.pageid = 10320641804;
                    self.hpageid = 10320641804;
                } else {
                    self.pageid = 10320641805;
                    self.hpageid = 10320641805;
                }
                $('.view_header').css('background', '#394054'); //头部背景色
                $('.rob_detail_back').show();

                window.app.getDeviceInfoCallBack = function(data) {
                    var deviceInfo = JSON.parse(data);
                    //登录态获取
                    var userInfo,
                        deviceInfoVersion;

                    self.isNewAppVersion = deviceInfo.version < "2.0.0" ? false : true; //IM接入版本判断

                    deviceInfoVersion = deviceInfo.version;
                    if (deviceInfoVersion && !(deviceInfoVersion < "2.0.0")) {
                        native.hideHeader();

                        var robListcallback = function(data) {
                            cookieUserInfor = JSON.parse(data);
                            // if (userInfo) {
                            self.initOnShow(cookieUserInfor);
                            // }
                        };
                        self.callNativeUser(robListcallback); //2.0.0版本 Cookie userInfo set

                    } else {
                        self.initOnShow();
                    }
                };
                if (self.isInApp()) {
                    window.VAppUtil.getDeviceInfo(); //获取APP版本

                } else {
                    self.initOnShow();
                }

            },

            //渲染需求单详细信息
            renderContainer: function() {
                var self = this;
                var param = {
                    requireDetailId: Lizard.P("requireDetailId"),
                    orderType: Lizard.P("orderType")
                }

                if (Lizard.P('sourcefrom') && (Lizard.P('sourcefrom').toLowerCase() == 'wechat' || Lizard.P('sourcefrom').toLowerCase() == 'sms')) {
                    $.extend(param, {
                        platformProviderId: Lizard.P('providerid'),
                        platformUserId: Lizard.P('userid')
                    });
                    if ((Lizard.P('from') == undefined || (Lizard.P('from') != undefined && Lizard.P('from') != '' && Lizard.P('from') != null && Lizard.P('from').toLowerCase() != 'rob_list')) && Lizard.P('sourcefrom').toLowerCase() == 'wechat') {
                        $.extend(param, {
                            sourceFrom: Lizard.P('sourcefrom')
                        });
                    }
                }

                detailModel.setParam(param)
                mFacade.excute(self, detailModel, function(json) {
                    var detailTpl;

                    localStorage.setItem('dingzhi_UserID', json.UserID);
                    self.$el.find('.rob_success_tip').hide();
                    self.$el.find('.refuse_success_tip').hide();


                    // if (json.IsShowDiverte == 'F') {
                    //     isNewVersion = true;
                    //     self.$el.find('.rob_limit_tip').html(_.template(orderSupple)({
                    //         "data": json
                    //     })).show();
                    //     if (self.isIOS) {
                    //         //self.$el.find('.rob_limit_tip .cgdes_con01').addClass('ios_cgdes_con01');
                    //     }
                    //     if (json.RobOrderSurplusCount > 0) {
                    //         self.timeCount(8000);
                    //     }
                    //     self.myTracklog({
                    //         biz: 'robDetailNew'
                    //     });
                    // } else if (json.IsShowDiverte == 'T') {
                    //     self.myTracklog({
                    //         biz: 'robDetailOld'
                    //     });
                    // }
                    if (json.OrderType == 'GrabOrder') {
                        detailTpl = orderDetail_A;

                    } else if (json.OrderType == 'TurnOrder') {
                        detailTpl = orderDetail_B;
                    }
                    self.$el.find('.detail_container').html(_.template(detailTpl)({
                        "data": json
                    }));

                    $('.j_imChat').attr('data-uid', json.UserProfile.Uid);

                    try {
                        if (self.$el.find('.user_profile_exposure').length > 0) {
                            self.myTracklog({
                                biz: 'userProfileExposure',
                                generous: self.$el.find('.generous_i') ? self.$el.find('.generous_i').html() : 0,
                                price: self.$el.find('.price_sensitive_i') ? self.$el.find('.price_sensitive_i').html() : 0,
                                grade: self.$el.find('.grade_i') ? self.$el.find('.grade_i').html() : 0
                            });
                        }
                    } catch (e) {}


                    self.$el.find('#confirmErrorTip').hide();
                }, function(obj, e) {
                    //网络出现问题，把弹层都关闭掉
                    self.$el.find('.rob_success_tip').hide();
                    self.$el.find('.refuse_success_tip').hide();
                    self.$el.find('#confirmErrorTip').hide();
                }, false, isIgnoreLogin)
            },

            //IOS app头部样式处理
            headFix: function() {
                var self = this;
                // if (self.isInApp() && self.isIOS) {
                // self.$el.find('.view_header').addClass('detail_header_iosapp')
                // }
                //微信推送消息和短信来源的隐藏回退按钮
                if (Lizard.P('sourcefrom') && (Lizard.P('sourcefrom').toLowerCase() === 'wechat' || Lizard.P('sourcefrom').toLowerCase() === 'sms') && Lizard.P('from') != 'rob_list') {
                    self.$el.find('.rob_detail_back').hide();
                }
            },

            timeCount: function(time) {
                var self = this;
                time = isNaN(time) ? 8000 : time;
                var timeInterval = setInterval(function() {
                    self.$el.find('.js_time_count').html(Math.round(time / 1000) + '秒后自动关闭');
                    time -= 1000;
                    if (Math.round(time / 1000) <= 0) {
                        clearInterval(timeInterval);
                    }
                    if (time <= 0) {
                        var timeOut = setTimeout(function() {
                            self.$el.find('.rob_limit_tip').hide();
                            clearTimeout(timeOut);
                        }, 1000)
                    }
                }, 1000)
            },

            closeRobLimitTip: function(e) {
                var self = this;
                self.$el.find('.rob_limit_tip').hide();
                self.myTracklog({
                    biz: 'closeRobLimitTip'
                });
            },

            goToImproveDemand: function() {
                var self = this,
                    from = Lizard.P('from'),
                    requireDetailId = Lizard.P('requireDetailId');

                if (isIgnoreLogin) {
                    Lizard.goTo("improveDemand?sourceFrom=" + Lizard.P('sourceFrom') + '&providerid=' + Lizard.P('providerid') + '&userid=' + Lizard.P('userid') + '&requireDetailId=' + Lizard.P('requireDetailId') + '&orderType=' + Lizard.P('orderType') + '&from=' + from, {
                        "loading": false
                    });

                } else {
                    Lizard.goTo("improveDemand?fromPage=rob_detail" + '&requireDetailId=' + Lizard.P('requireDetailId') + '&orderType=' + Lizard.P('orderType') + '&from=' + from, {
                        "loading": false
                    });
                }

            },

            getQueryString: function(name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]);
                return null;
            }
        })

    });